#!/usr/bin/env ruby require 'rubygems' # Require useful libs require 'pp' require 'rest-open-uri' require 'json' ; require 'sha1' ; require 'cgi' require 'brl/util/util' # Set some key vars to use in making resource URI host = 'proline.brl.bcm.tmc.edu' usr = 'andrewj' pwd = 'andrewj_123' grp = 'ARJ' db = 'Empty' prj = 'Test YesEsc 1' # Get our annos as a multi-line LFF String lffs = File.read('./exampleUpload.lff') # What's our -rsrcURI- (everything but the auth params) # - this example gets a project description # - note ends with ?, even though no URL params -yet-. But # -always- will be some params so need '?'. I think missing # "?" will be source of bug for many people. rsrcURI = "http://#{host}/REST/v1/grp/#{CGI.escape(grp)}/db/#{CGI.escape(db)}/annos?" # Must computer AUTHENTICATION parameter values to add to # the end of our resource URI: # # 1) Compute digested user+pass usrpw = SHA1.hexdigest("#{usr}#{pwd}") # 2) Compute gbToken, saving the current time as a side effect gbToken = SHA1.hexdigest(rsrcURI + usrpw + (gbTime=Time.now.to_i.to_s)) # Now construct the final URI to actually use in request: # # Make fullURI (rsrcURI + auth params) fullURI = "#{rsrcURI}gbLogin=#{usr}&gbTime=#{gbTime}&gbToken=#{gbToken}" # Get data from Genboree using HTTP GET request to fullURI # - few ways of doing this; we'll use open-uri but we need to # make sure debug messages are available from server # - can also use Net::HTTP to do this, which is good for # large downloads and uploads of big data # - the nil assignment makes sure the vars will not # have leftovers from previously running this line in irb # (e.g. if failure, repIO can have non-nil from -previous- # successful call you made earlier in irb). begin repIO = err = nil repIO = open(fullURI, :method => :put, :body => lffs) rescue => err end # repIO should be IO class (eg StringIO) if success # - read from it to get body # If any NON success (non 200), and there are several # possible), you'll want to examine err. Specifically, # get the payload with the representation from err.io.read() # Payloads are all JSON (except when getting LFF or other # special data representations...see Help page), so to make # them Ruby arrays or hashes, parse the payloads using # JSON library: successObj = JSON.parse(repIO.read) if(repIO) failObj = JSON.parse(err.io.read) unless(repIO) # <your code here> # I would check if an error occurred or not and maybe print # a message to stderr if repIO is nil. For JSON [i.e. most] # representations, you will want to examine/print: # if(repIO.nil?) $stderr.puts failObj['status']['statusCode'] $stderr.puts failObj['status']['msg'] else pp successObj['status'] end